﻿@inherits RazorFunction

@functions {
	public override string FunctionDescription
	{
        get { return "Show random image"; }
	}

    [FunctionParameter(Label = "Images folder")]
    public DataReference<IMediaFileFolder> ImagesFolder { get; set; }
	
    
    private string InlineStyle(string imageId)
    {
        return (!string.IsNullOrEmpty(imageId) ? "background-image:url('~/media(" + imageId + ")');" : "");

    }
}
@{
    string folderPath = ImagesFolder.Data.Path;
    var image = Data.Get<IImageFile>().Where(i => i.FolderPath == folderPath).OrderBy(it => Guid.NewGuid()).FirstOrDefault();
    if (image == null)
    {
        return;
    }
}
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:f="http://www.composite.net/ns/function/1.0">
	<head>
	</head>
	<body>
        <div class="page-image c1-wide" style="@InlineStyle(image.Id.ToString())"></div>
	</body>
</html>
